﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Reflection;

namespace QL_Truong_Hoc.TuyenSinh
{
    public partial class frmVietPhieuVaoLop : DevExpress.XtraEditors.XtraForm
    {
        private const string mcstrRoleCode = "nhap_hoc";

        DTO.THocSinhDTO mobjHs = null;
        DTO.TDanhSachDuTuyenDTO mobjDs = null;
        private int mintTrinhDo = clsConst.gcintNoneValue;
        private int mintKDT = clsConst.gcintNoneValue;
        private int mintNghe = clsConst.gcintNoneValue;
        private int mintLopID = clsConst.gcintNoneValue;
        private stThuPhieu mstPhieu = new stThuPhieu();

        private int mintRowIndex;
        private int mintHsID;

        private struct stThuPhieu
        {
            public bool blnPhieuHocNghe;
            public bool blnTheHocNghe;
            public bool blnQDXuatNgu;
            public bool blnPhieuQuanNhan;
            public bool blnGiayCMND;
            public bool blnBangVanHoa;
            public bool blnGiayKhaiSinh;
            public bool blnAnh;
            public bool blnDaCapVPP;
        }

        public frmVietPhieuVaoLop()
        {
            InitializeComponent();
        }

        private void frmVietPhieuVaoLop_Load(object sender, EventArgs e)
        {
            if (!clsCommon.fncCheckRole(Program.glstRoles, mcstrRoleCode))
            {
                this.BeginInvoke(new MethodInvoker(this.Close));
                return;
            }

            // TODO: This line of code loads data into the 'qLTHDataSet.mDonViQuanDoi' table. You can move, or remove it, as needed.
            this.mDonViQuanDoiTableAdapter.Fill(this.qLTHDataSet.mDonViQuanDoi);
            // TODO: This line of code loads data into the 'qLTHDataSet.mNghe' table. You can move, or remove it, as needed.
            this.mNgheTableAdapter.Fill(this.qLTHDataSet.mNghe);
            // TODO: This line of code loads data into the 'qLTHDataSet.mTrinhDoDaoTao' table. You can move, or remove it, as needed.
            this.mTrinhDoDaoTaoTableAdapter.Fill(this.qLTHDataSet.mTrinhDoDaoTao);

            xInit();
        }

        private bool xInit()
        {
            bool blnResult = false;
            try
            {
                //list năm tuyển sinh là năm sau và 10 năm trc đó
                cbNamTuyenSinh.Properties.Items.Add(DateTime.Today.Year + 1);
                for (int i = 0; i <= 10; i++)
                {
                    cbNamTuyenSinh.Properties.Items.Add(DateTime.Today.Year - i);
                }
                cbNamTuyenSinh.SelectedIndex = 1;

                btnLuuPhieu.Enabled = false;

                return true;
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            return blnResult;
        }

        private bool xClear()
        {
            bool blnResult = false;
            try
            {
                mintLopID = clsConst.gcintNoneValue;
                txtTen.Text = "";
                txtHoDem.Text = "";
                txtNgaySinh.Text = "";
                txtCMND.Text = "";
                txtQueQuan.Text = "";

                lokDonVi.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
                lokDonVi.SendKey(new KeyEventArgs(Keys.Control | Keys.Delete));
                //lokDonVi.EditValue = clsConst.gcintNoneValue;

                lokNghe.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
                lokNghe.SendKey(new KeyEventArgs(Keys.Control | Keys.Delete));
                //lokNghe.EditValue = clsConst.gcintNoneValue;

                txtLop.Text = "";
                chkPhieu.UnCheckAll();

                txtDen.Text = "";
                txtGap.Text = "";

                mintTrinhDo = clsConst.gcintNoneValue;
                mintKDT = clsConst.gcintNoneValue;
                mintNghe = clsConst.gcintNoneValue;
                mintLopID = clsConst.gcintNoneValue;
                mstPhieu = new stThuPhieu();

                mintRowIndex = clsConst.gcintNoneValue;
                mintHsID = clsConst.gcintNoneValue;

                txtQDXN_So.Text = "";
                dtpQDXN_Ngay.EditValue = null;
                txtTheHocNghe_So.Text = "";
                dtpTheHocNghe_Ngay.EditValue = null;
                grpQDXuatNgu.Enabled = false;
                grpQDXuatNgu.Enabled = false;

                return true;
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            return blnResult;
        }

        private void btnDanhSach_Click(object sender, EventArgs e)
        {
            try
            {
                int intNam;
                string strDot;

                intNam = clsCommon.fncCnvNullToInt(cbNamTuyenSinh.Text.Trim());
                strDot = cbDotTuyenSinh.Text.Trim();

                this.tDanhSachDuTuyengetallwithdetailBindingSource.Filter = string.Format("NamTuyenSinh = {0} and DotTuyenSinh = '{1}' and NhapHoc = False", intNam, strDot);

                // TODO: This line of code loads data into the 'qLTHDataSet.tDanhSachDuTuyen_getallwithdetail' table. You can move, or remove it, as needed.
                this.tDanhSachDuTuyen_getallwithdetailTableAdapter.Fill(this.qLTHDataSet.tDanhSachDuTuyen_getallwithdetail);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void gridControlDanhSach_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                //chỉ kích hoạt với chuột trái
                if (e.Button != System.Windows.Forms.MouseButtons.Left) return;

                xClear();
                
                mintRowIndex = dgvDanhSach.FocusedRowHandle;
                mintHsID = clsCommon.fncCnvNullToInt(dgvDanhSach.GetFocusedRowCellValue(colHS_ID));
                mintTrinhDo = clsCommon.fncCnvNullToInt(dgvDanhSach.GetFocusedRowCellValue(colTD_ID));

                if (mintHsID <= 0)
                { return; }
                
                btnLuuPhieu.Enabled = true; 

                //lấy và fill các thông tin liên quan
                mobjDs = DAO.TDanhSachDuTuyenDAO.Select(Program.gobjDb, mintHsID);
                mobjHs = DAO.THocSinhDAO.Select(Program.gobjDb, mintHsID);
                txtHoDem.Text = mobjHs.Hs_hodem;
                txtTen.Text = mobjHs.Hs_ten;
                if (mobjHs.Hs_ngaysinh > DateTime.MinValue) txtNgaySinh.Text = mobjHs.Hs_ngaysinh.ToString("dd/MM/yyyy");
                txtCMND.Text = mobjHs.Hs_cmnd;
                txtQueQuan.Text = mobjHs.Hs_quequan;
                lokDonVi.EditValue = mobjHs.DV_ID;

                int i = 0; if (mobjDs.PhieuHocNghe) chkPhieu.Items[i].CheckState = System.Windows.Forms.CheckState.Checked;
                i++; if (mobjDs.TheHocNghe) chkPhieu.Items[i].CheckState = System.Windows.Forms.CheckState.Checked;
                i++; if (mobjDs.QuyetDinhXuatNgu) chkPhieu.Items[i].CheckState = System.Windows.Forms.CheckState.Checked;
                i++; if (mobjDs.PhieuQuanNhan) chkPhieu.Items[i].CheckState = System.Windows.Forms.CheckState.Checked;
                i++; if (mobjDs.CMND) chkPhieu.Items[i].CheckState = System.Windows.Forms.CheckState.Checked;
                i++; if (mobjDs.BangVanHoa) chkPhieu.Items[i].CheckState = System.Windows.Forms.CheckState.Checked;
                i++; if (mobjDs.BanSaoGiayKhaiSinh) chkPhieu.Items[i].CheckState = System.Windows.Forms.CheckState.Checked;
                i++; if (mobjDs.Anh) chkPhieu.Items[i].CheckState = System.Windows.Forms.CheckState.Checked;
                i++; if (mobjDs.DaCapVPP) chkPhieu.Items[i].CheckState = System.Windows.Forms.CheckState.Checked;

                txtQDXN_So.Text = mobjDs.QuyetDinhXuatNgu_So;
                if (mobjDs.QuyetDinhXuatNgu_Ngay > DateTime.MinValue) dtpQDXN_Ngay.EditValue = mobjDs.QuyetDinhXuatNgu_Ngay;
                txtTheHocNghe_So.Text = mobjDs.TheHocNghe_So;
                if (mobjDs.TheHocNghe_Ngay > DateTime.MinValue) dtpTheHocNghe_Ngay.EditValue = mobjDs.TheHocNghe_Ngay;
                
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnChonLop_Click(object sender, EventArgs e)
        {
            try
            {
                using (frmChonLopNghe frmLop = new frmChonLopNghe(mintTrinhDo))
                {
                    frmLop.ShowDialog();
                    if (!frmLop.Selected) return;
                    lokNghe.EditValue = frmLop.NgheID;
                    txtLop.Text = frmLop.LopTen;
                    lblTrinhDo.Text = string.Format("{0} - {1}", frmLop.KhoasTen, frmLop.TrinhDoDaoTaoTen);

                    //lưu giá trị
                    mintLopID = frmLop.LopID;
                    mintNghe = frmLop.NgheID;
                    mintKDT = frmLop.KhungDaoTaoID;
                }
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnLuuPhieu_Click(object sender, EventArgs e)
        {
            try
            {
                if (!validControlBlank.Validate()) return;

                xGetCheckListValue();

                if (xAddNew(mintHsID, mintLopID))
                {
                    clsCommon.fncMsgInfo("Làm thủ tục thành công.");
                    dgvDanhSach.DeleteRow(mintRowIndex);
                    //xClear();
                    btnLuuPhieu.Enabled = false;
                }
                else
                {
                    clsCommon.fncMsgInfo("Làm thủ tục không thành công. Xin hãy thử lại.");
                }
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private bool xAddNew(int intHsID, int intLopID)
        {
            bool blnResult = false;
            try
            {
                bool blnSuccess = true;

                Program.gobjTrans = Program.gobjConn.BeginTransaction();

                //học sinh lớp
                DTO.TLopHocSinhDTO objLop_Hocsinh = new DTO.TLopHocSinhDTO();
                objLop_Hocsinh.HS_ID = intHsID;
                objLop_Hocsinh.Lop_ID = intLopID;

                //cập nhật ds tuyển sinh -> đã tuyển + nhập học
                //DTO.TDanhSachDuTuyenDTO objDS = DAO.TDanhSachDuTuyenDAO.Select(Program.mobjDb, intHsID);
                mobjDs.TuyenSinh = true;
                mobjDs.NhapHoc = true;
                mobjDs.NG_ID = mintNghe;
                mobjDs.PhieuHocNghe = mstPhieu.blnPhieuHocNghe;
                mobjDs.TheHocNghe = mstPhieu.blnTheHocNghe;
                mobjDs.QuyetDinhXuatNgu = mstPhieu.blnQDXuatNgu;
                mobjDs.PhieuQuanNhan = mstPhieu.blnPhieuQuanNhan;
                mobjDs.CMND = mstPhieu.blnGiayCMND;
                mobjDs.BangVanHoa = mstPhieu.blnBangVanHoa;
                mobjDs.BanSaoGiayKhaiSinh = mstPhieu.blnGiayKhaiSinh;
                mobjDs.Anh = mstPhieu.blnAnh;
                mobjDs.DaCapVPP = mstPhieu.blnDaCapVPP;

                mobjDs.QuyetDinhXuatNgu_So = "";
                mobjDs.QuyetDinhXuatNgu_Ngay = DateTime.MinValue;
                mobjDs.TheHocNghe_So = "";
                mobjDs.TheHocNghe_Ngay = DateTime.MinValue;

                if (mobjDs.QuyetDinhXuatNgu)
                {
                    mobjDs.QuyetDinhXuatNgu_So = txtQDXN_So.Text.Trim();
                    mobjDs.QuyetDinhXuatNgu_Ngay = clsCommon.fncCnvNullToDatetime(dtpQDXN_Ngay.EditValue);
                }

                if (mobjDs.TheHocNghe)
                {
                    mobjDs.TheHocNghe_So = txtTheHocNghe_So.Text.Trim();
                    mobjDs.TheHocNghe_Ngay = clsCommon.fncCnvNullToDatetime(dtpTheHocNghe_Ngay.EditValue);
                }

                //lấy số môn học sinh cần phải học
                List<DTO.MKhungDaoTaoMonDTO> objMonNghe = DAO.MKhungDaoTaoMonDAO.SelectWhere(Program.gobjDb, "KDT_ID = " + mintKDT);

                //object môn học mỗi học sinh
                DTO.THocSinhMonDTO objHsMonNghe = new DTO.THocSinhMonDTO();
                objHsMonNghe.HS_ID = intHsID;
                objHsMonNghe.HSM_hoc = true;

                //thêm môn + điểm văn hóa cho mỗi học sinh trung cấp
                DTO.THocSinhMonVanHoaDTO objHsMonVH = null;
                DTO.THocSinhDiemTotNghiepVanHoaDTO objHsDiemTNVH = null;
                List<DTO.MCapDoVanHoaDTO> lstCapDoVH = null;
                List<DTO.MMonVanHoaDTO> lstMonVH = null;
                if (mintTrinhDo == (int)clsEnum.TRINH_DO_DAO_TAO.TRUNG_CAP)
                {
                    objHsMonVH = new DTO.THocSinhMonVanHoaDTO();
                    objHsDiemTNVH = new DTO.THocSinhDiemTotNghiepVanHoaDTO();
                    lstCapDoVH = DAO.MCapDoVanHoaDAO.SelectAll(Program.gobjDb);
                    lstMonVH = DAO.MMonVanHoaDAO.SelectAll(Program.gobjDb);
                    objHsMonVH.HS_ID = intHsID;
                }

                //thêm diem tốt nghiệp cho mỗi hs.
                DTO.THocSinhDiemTotNghiepDTO objHsDiemTN = new DTO.THocSinhDiemTotNghiepDTO();
                objHsDiemTN.HS_ID = intHsID;
                objHsDiemTN.LanThi_ID = 1;

                //thêm điểm tổng kết cho mỗi hs.
                DTO.THocSinhTongKetDTO objHsTongKet = new DTO.THocSinhTongKetDTO();
                objHsTongKet.HS_ID = intHsID;

                try
                {
                    //thêm học sinh vào lớp, cập nhật danh sách dự tuyển thành "đã tuyển"
                    blnSuccess = blnSuccess && DAO.TLopHocSinhDAO.Insert(Program.gobjDb, Program.gobjTrans, objLop_Hocsinh);
                    blnSuccess = blnSuccess && DAO.TDanhSachDuTuyenDAO.Update(Program.gobjDb, Program.gobjTrans, mobjDs);
                    blnSuccess = blnSuccess && DAO.THocSinhTongKetDAO.Insert(Program.gobjDb, Program.gobjTrans, objHsTongKet);

                    //thêm môn nghề
                    for (int i = 0; i <= objMonNghe.Count - 1; i++)
                    {
                        if (!blnSuccess) break;
                        objHsMonNghe.MO_ID = objMonNghe[i].MO_ID;
                        blnSuccess = blnSuccess && DAO.THocSinhMonDAO.Insert(Program.gobjDb, Program.gobjTrans, objHsMonNghe);
                    }

                    //thêm môn văn hóa
                    if (mintTrinhDo == (int)clsEnum.TRINH_DO_DAO_TAO.TRUNG_CAP)
                    {
                        for (int i = 0; i <= lstCapDoVH.Count - 1; i++)
                        {
                            if (!blnSuccess) break;
                            for (int j = 0; j <= lstMonVH.Count - 1; j++)
                            {
                                if (!blnSuccess) break;
                                objHsMonVH.CDVH_ID = lstCapDoVH[i].CDVH_ID;     //cấp độ văn hóa
                                objHsMonVH.MVH_ID = lstMonVH[j].MVH_ID;         //môn văn hóa
                                blnSuccess = blnSuccess && DAO.THocSinhMonVanHoaDAO.Insert(Program.gobjDb, Program.gobjTrans, objHsMonVH);
                            }
                        }

                        //thêm bản ghi lưu điểm tốt nghiệp văn hóa 3 môn: toán lý hóa
                        objHsDiemTNVH.HS_ID = intHsID;
                        objHsDiemTNVH.Tnvh_diemtotnghiep = 0.0F;

                        objHsDiemTNVH.MVH_ID = (int)clsEnum.MON_VAN_HOA.TOAN;
                        blnSuccess = blnSuccess && DAO.THocSinhDiemTotNghiepVanHoaDAO.Insert(Program.gobjDb, Program.gobjTrans, objHsDiemTNVH);

                        objHsDiemTNVH.MVH_ID = (int)clsEnum.MON_VAN_HOA.LY;
                        blnSuccess = blnSuccess && DAO.THocSinhDiemTotNghiepVanHoaDAO.Insert(Program.gobjDb, Program.gobjTrans, objHsDiemTNVH);

                        objHsDiemTNVH.MVH_ID = (int)clsEnum.MON_VAN_HOA.HOA;
                        blnSuccess = blnSuccess && DAO.THocSinhDiemTotNghiepVanHoaDAO.Insert(Program.gobjDb, Program.gobjTrans, objHsDiemTNVH);
                
                    }

                    //thêm môn tốt nghiệp
                    objHsDiemTN.Mon_ID = (int)clsEnum.MON_TOT_NGHIEP.LY_THUYET;
                    blnSuccess = blnSuccess && DAO.THocSinhDiemTotNghiepDAO.Insert(Program.gobjDb, Program.gobjTrans, objHsDiemTN);
                    objHsDiemTN.Mon_ID = (int)clsEnum.MON_TOT_NGHIEP.THUC_HANH;
                    blnSuccess = blnSuccess && DAO.THocSinhDiemTotNghiepDAO.Insert(Program.gobjDb, Program.gobjTrans, objHsDiemTN);
                    objHsDiemTN.Mon_ID = (int)clsEnum.MON_TOT_NGHIEP.CHINH_TRI;
                    blnSuccess = blnSuccess && DAO.THocSinhDiemTotNghiepDAO.Insert(Program.gobjDb, Program.gobjTrans, objHsDiemTN);
                    objHsDiemTN.Mon_ID = (int)clsEnum.MON_TOT_NGHIEP.KY_NANG_TONG_HOP;
                    blnSuccess = blnSuccess && DAO.THocSinhDiemTotNghiepDAO.Insert(Program.gobjDb, Program.gobjTrans, objHsDiemTN);

                    if (blnSuccess) { Program.gobjTrans.Commit(); return true; }
                    else { Program.gobjTrans.Rollback(); }
                }
                catch { Program.gobjTrans.Rollback(); }
            }
            catch (Exception ex)
            {
                clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message);
                clsCommon.fncMsgError("Lưu dữ liệu không thành công. Hãy kiểm tra dữ liệu và thử lại.");
            }
            return blnResult;
        }

        private void btnTaoPhieu_Click(object sender, EventArgs e)
        {
            DataTable objData = null;

            try
            {
                if (!validControlBlank.Validate()) return;

                #region Lấy thông tin checkbox

                xGetCheckListValue();

                #endregion

                #region Tạo dữ liệu để export

                //tạo data
                objData = new DataTable();
                objData.Columns.Add("HoTen");
                objData.Columns.Add("NgaySinh");
                objData.Columns.Add("SoCMND");
                objData.Columns.Add("QueQuan");
                objData.Columns.Add("DonVi");
                objData.Columns.Add("TenNghe");
                objData.Columns.Add("PhieuHocNghe");
                objData.Columns.Add("TheHocNghe");
                objData.Columns.Add("QDXuaNgu");
                objData.Columns.Add("PhieuQuanNhan");
                objData.Columns.Add("GiayCMND");
                objData.Columns.Add("BangVanHoa");
                objData.Columns.Add("GiayKhaiSinh");
                objData.Columns.Add("Anh");
                objData.Columns.Add("Den");
                objData.Columns.Add("Gap");
                objData.Columns.Add("DaCapVPP");
                objData.Columns.Add("NgayHnay");
                objData.Columns.Add("ThangHnay");
                objData.Columns.Add("NamHnay");

                DataRow objRow = objData.NewRow();
                objRow["HoTen"] = txtHoDem.Text + " " + txtTen.Text;
                objRow["NgaySinh"] = txtNgaySinh.Text;
                objRow["SoCMND"] = txtCMND.Text;
                objRow["QueQuan"] = txtQueQuan.Text;
                objRow["DonVi"] = lokDonVi.Properties.GetDisplayText(lokDonVi.EditValue);
                objRow["TenNghe"] = lokNghe.Properties.GetDisplayText(lokNghe.EditValue);
                objRow["PhieuHocNghe"] = mstPhieu.blnPhieuHocNghe;
                objRow["TheHocNghe"] = mstPhieu.blnTheHocNghe;
                objRow["QDXuaNgu"] = mstPhieu.blnQDXuatNgu;
                objRow["PhieuQuanNhan"] = mstPhieu.blnPhieuQuanNhan;
                objRow["GiayCMND"] = mstPhieu.blnGiayCMND;
                objRow["BangVanHoa"] = mstPhieu.blnBangVanHoa;
                objRow["GiayKhaiSinh"] = mstPhieu.blnGiayKhaiSinh;
                objRow["Anh"] = mstPhieu.blnAnh;

                objRow["Den"] = "........";
                if (!clsCommon.fncIsBlank(txtDen.Text.Trim())) objRow["Den"] = txtDen.Text.Trim();

                objRow["Gap"] = "..........................................";
                if (!clsCommon.fncIsBlank(txtGap.Text.Trim())) objRow["Gap"] = txtGap.Text.Trim();

                objRow["DaCapVPP"] = mstPhieu.blnDaCapVPP;
                objRow["NgayHnay"] = DateTime.Today.Day;
                objRow["ThangHnay"] = DateTime.Today.Month;
                objRow["NamHnay"] = DateTime.Today.Year;

                objData.Rows.Add(objRow);

                #endregion

                Export.clsExportPhieuVaoLop objExport = new Export.clsExportPhieuVaoLop();
                objExport.fncExport(this.docPhieuVaoLop, objData);
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            finally { if (objData != null) objData.Dispose(); }
        }

        private bool xGetCheckListValue()
        {
            bool blnResult = false;
            try
            {
                string strTemp;
                for (int i = 0; i <= chkPhieu.Items.Count - 1; i++)
                {
                    strTemp = chkPhieu.Items[i].Description;
                    switch (strTemp)
                    {
                        case "Phiếu học nghề":
                            mstPhieu.blnPhieuHocNghe = false;
                            if (chkPhieu.Items[i].CheckState == CheckState.Checked) mstPhieu.blnPhieuHocNghe = true;
                            break;

                        case "Thẻ học nghề":
                            mstPhieu.blnTheHocNghe = false;
                            if (chkPhieu.Items[i].CheckState == CheckState.Checked) mstPhieu.blnTheHocNghe = true;
                            break;

                        case "Quyết định xuất ngũ":
                            mstPhieu.blnQDXuatNgu = false;
                            if (chkPhieu.Items[i].CheckState == CheckState.Checked) mstPhieu.blnQDXuatNgu = true;
                            break;

                        case "Phiếu quân nhân":
                            mstPhieu.blnPhieuQuanNhan = false;
                            if (chkPhieu.Items[i].CheckState == CheckState.Checked) mstPhieu.blnPhieuQuanNhan = true;
                            break;

                        case "CMND":
                            mstPhieu.blnGiayCMND = false;
                            if (chkPhieu.Items[i].CheckState == CheckState.Checked) mstPhieu.blnGiayCMND = true;
                            break;

                        case "Bằng văn hóa":
                            mstPhieu.blnBangVanHoa = false;
                            if (chkPhieu.Items[i].CheckState == CheckState.Checked) mstPhieu.blnBangVanHoa = true;
                            break;

                        case "Bản sao giấy khai sinh":
                            mstPhieu.blnGiayKhaiSinh = false;
                            if (chkPhieu.Items[i].CheckState == CheckState.Checked) mstPhieu.blnGiayKhaiSinh = true;
                            break;

                        case "Ảnh":
                            mstPhieu.blnAnh = false;
                            if (chkPhieu.Items[i].CheckState == CheckState.Checked) mstPhieu.blnAnh = true;
                            break;

                        case "Đã cấp văn phòng phẩm":
                            mstPhieu.blnDaCapVPP = false;
                            if (chkPhieu.Items[i].CheckState == CheckState.Checked) mstPhieu.blnDaCapVPP = true;
                            break;
                    }
                }

                return true;
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            return blnResult;
        }

        private void chkPhieu_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
        {
            try
            {
                if (chkPhieu.Items[1].CheckState == System.Windows.Forms.CheckState.Checked)
                    grpTheHocNghe.Enabled = true;
                else
                    grpTheHocNghe.Enabled = false;

                if (chkPhieu.Items[2].CheckState == System.Windows.Forms.CheckState.Checked)
                    grpQDXuatNgu.Enabled = true;
                else
                    grpQDXuatNgu.Enabled = false;
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

    }
}